package com.breaktian.assemble.customviews.viewpager.bannerviewpager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import com.breaktian.assemble.R;

import java.util.List;

/**
 * Created by tiankeke on 2017/6/15.
 * 入口类
 */

public class AutoBannerView<T> extends RelativeLayout {
    private Context mContext;
    private View rootView;
    private BannerViewPager bannerViewPager;
    private PageDotView dotView;
    private BannerPagerAdapter<T> mAdapter;

    public AutoBannerView(Context context) {
        super(context);
        init(context);
    }

    public AutoBannerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public AutoBannerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        rootView = LayoutInflater.from(context).inflate(R.layout.bm_layout_auto_banner_view,this);
        bannerViewPager = (BannerViewPager)rootView.findViewById(R.id.bannerViewPager);
        dotView = (PageDotView)rootView.findViewById(R.id.dotView);
    }

    public void setAdapter(BannerPagerAdapter<T> adapter){
        this.mAdapter = adapter;
        bannerViewPager.setAdapter(adapter);
        dotView.setDotSize(BannerPagerAdapter.DATA_SIZE);
        bannerViewPager.bindDotView(dotView);
        if(BannerPagerAdapter.DATA_SIZE==1){
            stopAutoScroll();
        }
    }

    public void setData(List<T> data){
        mAdapter.setData(data);
        dotView.setDotSize(BannerPagerAdapter.DATA_SIZE);
        bannerViewPager.bindDotView(dotView);
        if(BannerPagerAdapter.DATA_SIZE==1){
            stopAutoScroll();
        }
    }

    public void startAutoScroll(){
        bannerViewPager.startAutoScroll();
    }

    public void stopAutoScroll(){
        bannerViewPager.stopAutoScroll();
    }


}
